<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<script type="text/javascript">
function fetch(){
	var username = $("#username_${timer }").val();
	var password = $("#password_${timer }").val();
	var web = $("#web_${timer }").val();
	if(isBlank(username) || isBlank(password) || isBlank(web)){
		jfinal.easyAlert("username or password or web is blank");
	}else{
		var url = '${contextPath }/${model }/fetch';
		var params = {};
		params.username = username;
		params.password = password;
		params.op = 'getCheckCode';
		params.web = web;
		jfinal.showProcess("正在获取验证码");
		jfinal.ajaxPost(url, params, function(data){
			jfinal.closeProgress();
			if(data.operate == 'inputCode'){
				showCheckCodeDlg(data.codeImg);
			}else{
				jfinal.easyAlert(data.error);
			}
		});
	}
}
/**
 * 验证码对话框
 * */
function showCheckCodeDlg(base64ImgStr){
	if(base64ImgStr != null){
		$("#checkCode_${timer}").val("");
		$("#imgCheckCode_${timer }").attr("src", "data:image/jpg;base64," + base64ImgStr);
	}
	$("#divCheckCode_${timer}").show();
	$('#divCheckCode_${timer}').dialog({
		title : '验证码',
		maximizable : true,
		width : 250,
		modal : true
	}).dialog('open').error(function() {
		//$.messager.progress('close');
		//$.messager.alert('登录错误', '获取验证码图片失败！', 'error');
	});
}
function doLoginBycheckCode(){
	var username = $("#username_${timer }").val();
	var password = $("#password_${timer }").val();
	var web = $("#web_${timer }").val();
	var url = "${contextPath }/${model }/fetch";
	var params = {};
	params.username = username;
	params.password = password;
	params.web = web ;
	params.checkCode = $("#checkCode_${timer}").val();
	params.op = 'login';
	jfinal.showProcess("正在登陆");
	jfinal.ajaxPost(url, params, function(data){
		jfinal.closeProgress();
		if(data.operate){
			$('#divCheckCode_${timer}').dialog().dialog('close');
			params.op = "fetch" ;
			jfinal.showProcess("正在采集数据...请耐心等待");
			jfinal.ajaxPost(url, params, function(dataT){
				jfinal.closeProgress();
				jfinal.easyAlert(dataT.operate);
			});
		}else{
			alert(data.error);
		}
	});
}
function doRefreshCode(){
	fetch();
}
</script>
<div id="tb_${timer }">
	<div id="tb" style="padding:5px;height:auto">
        <div style="margin-bottom:5px">
        <form id="inputFrom_${timer }" action="">
        <table style="border: solid #000 1px; width: 100%">
        	<tr>
        		<td style="text-align:center">
        			<input class="easyui-validatebox" hidden="hidden"  style="width: 100px;" value="JD" name="web" id="web_${timer }" />
        			京东商城
        		</td>
        	</tr>
        	<tr>
				<td style="text-align:center">
					用户名:<input class="easyui-validatebox" name="username" id="username_${timer }" />
					密码:<input class="easyui-validatebox" type="password"  name="password" id="password_${timer }" />
					<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="fetch()" >开始采集</a>
				</td>
        	</tr>
        </table>
        </form>
        </div>
        <div style="margin-bottom:5px">
         <form id="queryFrom_${timer }" action="">
	        	查询条件: <input class="easyui-validatebox" style="width: 100px;" name="loginName_string_like" />
	            <a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="jfinal.onQuery('queryFrom_${timer }', 'dg_${timer }')" >查询</a>
	            <a href="#" class="easyui-linkbutton" iconCls="icon-reload" onclick="jfinal.onReset('queryFrom_${timer }', 'dg_${timer }')" >重置</a>
	     </form>
	    </div>
    </div>
</div>

<!-- 输入验证码窗口 -->
<div id = "divCheckCode_${timer}" style="display: none">
	<form id="f_checkCode_${timer}">
		<table>
			<tr>
				<td>验证码：</td>
				<td><input type="text" id="checkCode_${timer}" name="checkCode"/></td>
			</tr>
			<tr>
				<td>图片:</td>
				<td><img src="#" id="imgCheckCode_${timer }" name="imgCheckCode" alt="点击刷新" onclick="javascript:doRefreshCode()"/></td>
			</tr>
			<tr>
				<td><input type="button" value="提交" onclick="javascript:doLoginBycheckCode()"/></td>
			</tr>
		</table>
	</form>
</div>
<div id="dialog_${timer }"></div>
<table id="dg_${timer }"></table>